<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class FmwVipController extends Controller
{
    protected $baseBillSn = '202409001'; // uat 测试站单据号
    protected $uatPoSn;
    protected $uatOrderSn;
    protected $uatOrderSn2;
    protected $uatReturnSn;
    protected $uatGoodBarCode = '8033153621527';
    protected $uatGoodBarCode2 = '8033153621350';

    public function token(Request $request)
    {
        return [
            "access_token" => "1AACCBFDB83FB46B426E1FEAFA00EA37DBE00C1A",
            "expires_in" => 7776000,
            "open_id" => "1201",
            "refresh_expires_time" => 1744887928000,
            "refresh_token" => "SXY5WNYNJWABXBKVIMZALPZ9H4C7BAKNFV6QT8PB"
        ];
    }

    public function index(Request $request)
    {
        $method = $request->get('method');
        if (empty($method)) {
            return [];
        }

        if (!method_exists($this, $method)) {
            echo sprintf("[%s] mock function not exists", $method);
            exit;
        }

        $this->uatPoSn = sprintf('%s001', $this->baseBillSn);
        $this->uatOrderSn = sprintf('VIP%s0001', $this->baseBillSn);
        $this->uatOrderSn2 = sprintf('VIPJIT%s001', $this->baseBillSn);
        $this->uatReturnSn = sprintf('%sR02501CD', $this->baseBillSn);

        return $this->$method($request);
    }

    public function refreshToken(Request $request)
    {
        return [
            'returnCode' => '0',
            'result' => [
                "access_token" => "1AACCBFDB83FB46B426E1FEAFA00EA37DBE00C1A",
                "create_at" => date('Y-m-d H:i:s'),
                "expires_in" => 7776000,
                "expires_time" => date('Y-m-d H:i:s', time() + 7776000),
                "is_expired" => false,
                "refresh_expires_time" => '2025-04-17 19:05:28',
                "refresh_token" => "SXY5WNYNJWABXBKVIMZALPZ9H4C7BAKNFV6QT8PB",
                "status" => ''
            ]
        ];
    }

    public function getSkuInfo(Request $request)
    {
        $req = $request->get('request');
        $barcode = $req['barcode'];

        $list = [];
        if ($barcode == '8033153822901') {
            $list[] = [
                'barcode' => '8033153822901',
                'product_name' => '唯品会测试商品A01',
                'sn' => '23P_31W5U104I_01A',
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ];
        } elseif ($barcode == '8033153822902') {
            $list[] = [
                'barcode' => '8033153822902',
                'product_name' => '唯品会测试商品A02',
                'sn' => '23P_31W5U104I_01A',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ];
        }

        return [
            'returnCode' => '0',
            'result' => $list
        ];
    }

    public function getSkuList(Request $request)
    {
        $req = $request->get('criteria');
        $vendor_id = $req['vendor_id'];
        $barcode = isset($req['barcode']) ? $req['barcode'] : '';
        $page = $request->get('page');

        if ($vendor_id == 560) {
            return $this->_releaseGetSkuList($barcode, $page);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetSkuList($barcode, $page);
        }

        $sku1 = [
            'barcode' => '8033153822901',
            'product_name' => '唯品会测试商品A01',
            'sn' => '23P_31W5U104I_01A',
            'selling_status' => 1,
            'cooperation_no' => '30011001',
            'warehouse' => '',
            'latest_update_time' => 1713351928
        ];
        $sku2 = [
            'barcode' => '8033153822902',
            'product_name' => '唯品会测试商品A02',
            'sn' => '23P_31W5U104I_01A',
            'selling_status' => 1,
            'cooperation_no' => '30011001',
            'warehouse' => '',
            'latest_update_time' => 1713351928
        ];

        $list = [];
        if ($barcode) {
            if ($barcode == $sku1['barcode']) {
                $list[] = $sku1;
            }
            if ($barcode == $sku2['barcode']) {
                $list[] = $sku2;
            }
        } else {
            if ($page == 1) {
                $list[] = $sku1;
                $list[] = $sku2;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'has_next' => false,
                'list' => $list
            ]
        ];
    }

    private function _releaseGetSkuList($barcode, $page)
    {
        $vip_list = [
            [
                'barcode' => '8033153888234',
                'product_name' => '唯品会23P_5OHEDQ037_901_M商品',
                'sn' => '23P_5OHEDQ037_901',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153888241',
                'product_name' => '唯品会23P_5OHEDQ037_901_S商品',
                'sn' => '23P_5OHEDQ037_901',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033152942487',
                'product_name' => '唯品会23A_40K6DF046_100_46商品',
                'sn' => '23A_40K6DF046_100',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153205413',
                'product_name' => '唯品会23A_40K6DF046_252_44商品',
                'sn' => '23A_40K6DF046_252',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153490765',
                'product_name' => '唯品会23P_481YDV04I_101_S商品',
                'sn' => '23P_481YDV04I_101',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153694002',
                'product_name' => '唯品会23P_58Z2UQ00W_80P_S商品',
                'sn' => '23P_58Z2UQ00W_80P',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153425514',
                'product_name' => '唯品会23P_499PU9001_907_44商品',
                'sn' => '23P_499PU9001_907',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033262314204',
                'product_name' => '唯品会22A_103FE200L_901_S商品',
                'sn' => '22A_103FE200L_901',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153969759',
                'product_name' => '唯品会23P_3089J3179_00D_XL商品',
                'sn' => '23P_3089J3179_00D',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153574403',
                'product_name' => '唯品会23P_347BU3011_910_XL商品',
                'sn' => '23P_347BU3011_910',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
            [
                'barcode' => '8033153850484',
                'product_name' => '唯品会23P_4CDR558R5_217_44商品',
                'sn' => '23P_4CDR558R5_217',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => 1713351928
            ],
        ];

        return $this->_buildGetSkuList($barcode, $page, $vip_list);
    }

    public function getJitXOrdersAndPrice(Request $request)
    {
        $req = $request->get('param');
        $vendor_id = $req['vendor_id'];
        $order_sn = isset($req['order_sns']) ? $req['order_sns'][0] : '';
        $page = $req['page'];

        if ($vendor_id == 560) {
            return $this->_releaseGetJitXOrdersAndPrice($order_sn, $page, $vendor_id);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetJitXOrdersAndPrice($order_sn, $page, $vendor_id);
        }

        $order1 = [
            "is_province_dw_order" => 0,
            "buyer_province" => "北京市",
            "transport_time" => "",
            "buyer_country_id" => "CN",
            "remark" => "",
            "forbidden_reason" => "",
            "transport_no" => "",
            "merged_sn" => "",
            "order_status" => "10",
            "delivery_kpi_start_time" => "",
            "buyer_mobile" => "166****6306",
            "order_goods" => [
                [
                    "vendor_code" => "550",
                    "quantity" => 1,
                    "anti_theft_flag" => "0",
                    "brand_name" => "测试品牌",
                    "product_name" => "唯品会测试商品A01",
                    "promotion_price" => "",
                    "size" => "XL",
                    "quality_check_type" => 0,
                    "price" => "100.00",
                    "vendor_id" => $vendor_id,
                    "check_items" => [],
                    "sn" => "23P_31W5U104I_01A",
                    "cooperation_no" => "30011001",
                    "quality_check_type_desc" => "",
                    "barcode" => "8033153822901",
                    "security_type" => 0,
                    "po_no" => "2100801101",
                ],
                [
                    "vendor_code" => "550",
                    "quantity" => 1,
                    "anti_theft_flag" => "0",
                    "brand_name" => "测试品牌",
                    "product_name" => "唯品会测试商品A02",
                    "promotion_price" => "",
                    "size" => "XXL",
                    "quality_check_type" => 0,
                    "price" => "120.00",
                    "vendor_id" => $vendor_id,
                    "check_items" => [],
                    "sn" => "23P_31W5U104I_01A",
                    "cooperation_no" => "30011001",
                    "quality_check_type_desc" => "",
                    "barcode" => "8033153822902",
                    "security_type" => 0,
                    "po_no" => "2100801101",
                ],
            ],
            "pay_type" => "微信支付app",
            "transport_day" => "送货时间不限",
            "parent_order_sn" => "",
            "cod_type" => "0",
            "is_forbidden_delivery" => 0,
            "is_pre_transport_no" => "0",
            "regular_delivery" => 0,
            "carrier_name" => "顺丰速运",
            "order_type" => 1,
            "buyer_county" => "朝阳区",
            "cod_money" => "0.00",
            "delivery_warehouse" => "VIPTEST01",
            "buyer_address" =>
                "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "buyer_postcode" => "100020",
            "action_list" => [],
            "vendor_name" => "TEST供应商",
            "old_order_sn" => "",
            "buyer_city" => "北京市",
            "buyer" => "ZH",
            "merged_code" => "2A12A2837A338DD33B49642313240001",
            "last_update_time" => date('Y-m-d H:i:s'),
            "buyer_tel" => "",
            "is_store_delivery" => 0,
            "vendor_id" => $vendor_id,
            "add_time" => date('Y-m-d H:i:s'),
            "order_sn" => "VIP202404221001",
            "carrier_code" => "",
        ];

        $total = 0;
        $orders = [];
        if ($order_sn) {
            if ($order_sn == $order1['order_sn']) {
                $total = 1;
                $orders[] = $order1;
            }
        } else {
            $total = 1;
            if ($page == 1) {
                $orders[] = $order1;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'orders' => $orders
            ]
        ];
    }

    private function _releaseGetJitXOrdersAndPrice($order_sn, $page, $vendor_id)
    {
        $order1 = [
            "is_province_dw_order" => 0,
            "buyer_province" => "北京市",
            "transport_time" => "",
            "buyer_country_id" => "CN",
            "remark" => "",
            "forbidden_reason" => "",
            "transport_no" => "",
            "merged_sn" => "",
            "order_status" => "10",
            "delivery_kpi_start_time" => "",
            "buyer_mobile" => "166****6306",
            "order_goods" => [
                [
                    "vendor_code" => (string)$vendor_id,
                    "quantity" => 1,
                    "anti_theft_flag" => "0",
                    "brand_name" => "测试品牌",
                    "product_name" => "唯品会23P_347BU3011_910_XL商品",
                    "promotion_price" => "",
                    "size" => "XL",
                    "quality_check_type" => 0,
                    "price" => "165.32",
                    "vendor_id" => $vendor_id,
                    "check_items" => [],
                    "sn" => "23P_347BU3011_910",
                    "cooperation_no" => "30011001",
                    "quality_check_type_desc" => "",
                    "barcode" => "8033153574403",
                    "security_type" => 0,
                    "po_no" => "2200801101",
                ]
            ],
            "pay_type" => "微信支付app",
            "transport_day" => "送货时间不限",
            "parent_order_sn" => "",
            "cod_type" => "0",
            "is_forbidden_delivery" => 0,
            "is_pre_transport_no" => "0",
            "regular_delivery" => 0,
            "carrier_name" => "",
            "order_type" => 1,
            "buyer_county" => "朝阳区",
            "cod_money" => "0.00",
            "delivery_warehouse" => "600185",
            "buyer_address" =>
                "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "buyer_postcode" => "100020",
            "action_list" => [],
            "vendor_name" => "贝纳通（上海）商贸有限公司",
            "old_order_sn" => "",
            "buyer_city" => "北京市",
            "buyer" => "ZH",
            "merged_code" => "2A12A2837A338DD33B49642313240001",
            "last_update_time" => date('Y-m-d H:i:s'),
            "buyer_tel" => "",
            "is_store_delivery" => 0,
            "vendor_id" => $vendor_id,
            "add_time" => date('Y-m-d H:i:s'),
            "order_sn" => "VIP02404251930000001",
            "carrier_code" => "",
        ];
        $order2 = [
            "is_province_dw_order" => 0,
            "buyer_province" => "北京市",
            "transport_time" => "",
            "buyer_country_id" => "CN",
            "remark" => "",
            "forbidden_reason" => "",
            "transport_no" => "",
            "merged_sn" => "",
            "order_status" => "10",
            "delivery_kpi_start_time" => "",
            "buyer_mobile" => "166****6306",
            "order_goods" => [
                [
                    "vendor_code" => (string)$vendor_id,
                    "quantity" => 1,
                    "anti_theft_flag" => "0",
                    "brand_name" => "测试品牌",
                    "product_name" => "唯品会23P_4CDR558R5_217_44商品",
                    "promotion_price" => "",
                    "size" => "44",
                    "quality_check_type" => 0,
                    "price" => "203.00",
                    "vendor_id" => $vendor_id,
                    "check_items" => [],
                    "sn" => "23P_4CDR558R5_217",
                    "cooperation_no" => "30011001",
                    "quality_check_type_desc" => "",
                    "barcode" => "8033153850484",
                    "security_type" => 0,
                    "po_no" => "2200801101",
                ]
            ],
            "pay_type" => "微信支付app",
            "transport_day" => "送货时间不限",
            "parent_order_sn" => "",
            "cod_type" => "0",
            "is_forbidden_delivery" => 0,
            "is_pre_transport_no" => "0",
            "regular_delivery" => 0,
            "carrier_name" => "",
            "order_type" => 1,
            "buyer_county" => "朝阳区",
            "cod_money" => "0.00",
            "delivery_warehouse" => "600185",
            "buyer_address" =>
                "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "buyer_postcode" => "100020",
            "action_list" => [],
            "vendor_name" => "贝纳通（上海）商贸有限公司",
            "old_order_sn" => "",
            "buyer_city" => "北京市",
            "buyer" => "ZH",
            "merged_code" => "2A12A2837A338DD33B49642313240001",
            "last_update_time" => date('Y-m-d H:i:s'),
            "buyer_tel" => "",
            "is_store_delivery" => 0,
            "vendor_id" => $vendor_id,
            "add_time" => date('Y-m-d H:i:s'),
            "order_sn" => "VIP02404251930000002",
            "carrier_code" => "",
        ];

        return $this->_buildGetJitXOrdersAndPrice($order_sn, $page, $order1, $order2);
    }

    public function getDeliveryOrders(Request $request)
    {
        $req = $request->get('param');
        $vendor_id = $req['vendor_id'];
        $page = $req['page'];

        if ($vendor_id == 560) {
            return $this->_releaseGetDeliveryOrders($page, $vendor_id);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetDeliveryOrders($page, $vendor_id);
        }

        $order1 = [
            "order_sn" => "VIP202404251001",
            "available_warehouses" => [
                "VIPTEST01"
            ],
            "status" => "NEW",
            "status_remark" => "新增",
            "buyer_address" => "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "update_time" => date('Y-m-d H:i:s'),
            "delivery_order_details" => [
                [
                    "brand_name" => "测试品牌",
                    "product_name" => "唯品会测试商品A01",
                    "barcode" => "8033153822901",
                    "size" => "XL",
                    "quantity" => 1,
                    "po_no" => "1705501101",
                    "cooperation_no" => "30011001",
                    "price" => "100.00"
                ]
            ],
            "vendor_id" => $vendor_id,
            "confirmed_delivery_warehouse" => "",
            "order_type" => 1,
            "buyer_province" => "北京市",
            "buyer_city" => "北京市",
            "buyer_county" => "朝阳区",
            "is_store_delivery" => 0,
            "root_order_sn" => ""
        ];

        $total = 1;
        $orders = [];
        if ($page == 1) {
            $orders[] = $order1;
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'delivery_orders' => $orders
            ]
        ];
    }

    private function _releaseGetDeliveryOrders($page, $vendor_id)
    {
        $order1 = [
            "order_sn" => "VIP02405251930000001",
            "available_warehouses" => [
                "600185"
            ],
            "status" => "NEW",
            "status_remark" => "新增",
            "buyer_address" => "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "update_time" => date('Y-m-d H:i:s'),
            "delivery_order_details" => [
                [
                    "brand_name" => "测试品牌",
                    "product_name" => "唯品会23P_347BU3011_910_XL商品",
                    "barcode" => "8033153574403",
                    "size" => "XL",
                    "quantity" => 1,
                    "po_no" => "2200801101",
                    "cooperation_no" => "30011001",
                    "price" => "165.32"
                ]
            ],
            "vendor_id" => $vendor_id,
            "confirmed_delivery_warehouse" => "",
            "order_type" => 1,
            "buyer_province" => "北京市",
            "buyer_city" => "北京市",
            "buyer_county" => "朝阳区",
            "is_store_delivery" => 0,
            "root_order_sn" => ""
        ];

        return $this->_buildGetDeliveryOrders($page, $order1);
    }

    public function feedbackDeliveryResult(Request $request)
    {
        $req = $request->get('request', []);
        $vendor_id = $req['vendor_id'];
        $results = $req['results'];

        $result = [];
        foreach ($results as $res) {
            $result[] = [
                'order_sn' => $res['order_sn'],
                'code' => 'SUCCESS',
                'msg' => '',
                'status' => 'SUCCESS'
            ];
        }

        return [
            'returnCode' => '0',
            'result' => $result
        ];
    }

    public function getPoList(Request $request)
    {
        $vendor_id = $request->get('vendor_id', '');
        $po_no = $request->get('po_no', '');
        $page = $request->get('page', 1);

        if ($vendor_id == 560) {
            return $this->_releaseGetPoList($po_no, $page);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetPoList($po_no, $page);
        }

        $po = [
            "vendor_name" => "TEST供应商",
            "brand_name" => "品牌",
            "warehouse" => "VIPTEST01",
            "schedule_name" => "TEST档期",
            "co_mode" => "jit",
            "trade_mode" => "",
            "po_start_time" => date('Y-m-d H:i:s'),
            "sell_et_time" => date('Y-m-d H:i:s', strtotime('+1 Year')),
            "not_pick" => "0",
            "stock" => "0",
            "schedule_id" => "17055001",
            "po_no" => "1705501101",
            "sell_st_time" => date('Y-m-d H:i:s'),
            "sales_volume" => "0",
            "cooperation_no" => "30011001",
        ];

        $total = 0;
        $purchase_order_list = [];
        if ($po_no && $po_no == $po['po_no']) {
            $total = 1;
            $purchase_order_list[] = $po;
        }
        if (!$po_no) {
            $total = 1;
            if ($page == 1) {
                $purchase_order_list[] = $po;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'purchase_order_list' => $purchase_order_list
            ]
        ];
    }

    private function _releaseGetPoList($po_no, $page)
    {
        $poList = [
            "vendor_name" => "贝纳通（上海）商贸有限公司",
            "brand_name" => "测试品牌",
            "warehouse" => "600185",
            "schedule_name" => "测试档期",
            "co_mode" => "jit",
            "trade_mode" => "",
            "po_start_time" => date('Y-m-d H:i:s'),
            "sell_et_time" => date('Y-m-d H:i:s', strtotime('+1 Year')),
            "not_pick" => "0",
            "stock" => "0",
            "schedule_id" => "22005001",
            "po_no" => "2200801101",
            "sell_st_time" => date('Y-m-d H:i:s'),
            "sales_volume" => "0",
            "cooperation_no" => "30011001",
        ];

        return $this->_buildGetPoList($po_no, $page, $poList);
    }

    public function createPick(Request $request)
    {
        $vendor_id = $request->get('vendor_id', '');
        $po_no = $request->get('po_no');
        $defaultWarehouse = 'VIPTEST01';
        if ($vendor_id == 560 || $vendor_id == 20240717) {
            $defaultWarehouse = '600185';
        }
        $warehouse = $request->get('warehouse', $defaultWarehouse);

        $warehouses = explode(',', $warehouse);
        if (count($warehouses) > 1) {
            return [
                'returnCode' => '0',
                'result' => []
            ];
        }

        $po_nos = explode(',', $po_no);
        $prefix = count($po_nos) == 1 ? 'PICK-' : 'MULPICK-';

        $pick = [
            'pick_no' => $prefix . implode('_', $po_nos),
            'pick_type' => 'jit',
            'warehouse' => $warehouse,
            'store_sn' => '',
            'jit_type' => '',
            'goods_type' => 0,
        ];
        $result = [];
        $result[] = $pick;

        return [
            'returnCode' => '0',
            'result' => $result
        ];
    }

    public function getPickDetail(Request $request)
    {
        $vendor_id = $request->get('vendor_id', '');
        $pick_no = $request->get('pick_no');
        $po_no = $request->get('po_no');
        $page = $request->get('page');

        if ($vendor_id == 560) {
            return $this->_releaseGetPickDetail($pick_no, $po_no, $page);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetPickDetail($pick_no, $po_no, $page);
        }

        $pick_product1 = [
            'barcode' => '8033153822901',
            'art_no' => '23P_31W5U104I_01A',
            'product_name' => '唯品会测试商品A01',
            'size' => '',
            'not_delivery_num' => 0,
            'security_type' => 0,
            'quality_check_flag' => 0,
            'stock' => 1
        ];
        $pick_product2 = [
            'barcode' => '8033153822902',
            'art_no' => '23P_31W5U104I_01A',
            'product_name' => '唯品会测试商品A02',
            'size' => '',
            'not_delivery_num' => 0,
            'security_type' => 0,
            'quality_check_flag' => 0,
            'stock' => 2
        ];

        $total = 2;
        $pick_product_list = [];

        $res = [
            'po_no' => $po_no,
            'sell_st_time' => date('Y-m-d H:i:s'),
            'sell_et_time' => date('Y-m-d H:i:s', strtotime('+1 Year')),
            'export_time' => "",
            'export_num' => 0,
            'warehouse' => 'VIPTEST01',
            'order_cate' => '',
            'total' => $total,
            'store_sn' => '',
            'jit_type' => ''
        ];

        if ($page == 1) {
            $pick_product_list[] = $pick_product1;
            $pick_product_list[] = $pick_product2;
        }
        $res['pick_product_list'] = $pick_product_list;

        return [
            'returnCode' => '0',
            'result' => $res
        ];
    }

    private function _releaseGetPickDetail($pick_no, $po_no, $page)
    {
        $pick_product1 = [
            'barcode' => '8033153574403',
            'art_no' => '23P_347BU3011_910',
            'product_name' => '唯品会23P_347BU3011_910_XL商品',
            'size' => 'XL',
            'not_delivery_num' => 0,
            'security_type' => 0,
            'quality_check_flag' => 0,
            'stock' => 5
        ];
        $pick_product2 = [
            'barcode' => '8033153850484',
            'art_no' => '23P_4CDR558R5_217',
            'product_name' => '唯品会23P_4CDR558R5_217_44商品',
            'size' => '44',
            'not_delivery_num' => 0,
            'security_type' => 0,
            'quality_check_flag' => 0,
            'stock' => 5
        ];

        return $this->_buildGetPickDetail($po_no, $page, $pick_product1, $pick_product2);
    }

    public function getMultiPoPickDetail(Request $request)
    {
        $req = $request->get('getPickDetailRequest');
        $vendor_id = $req['vendor_id'];
        $pick_sn = $req['pick_sn'];
        $page = $req['page'];

        list($prefix, $po_sns_str) = explode('-', $pick_sn);
        $po_sns = explode('_', $po_sns_str);

        if ($vendor_id == 560) {
            return $this->_buildGetMultiPoPickDetail();
        } else if ($vendor_id == 20240717) {
            return $this->_buildGetMultiPoPickDetail();
        }

        $pick_product1 = [
            'pick_no' => $pick_sn,
            'warehouse' => 'VIPTEST01',
            'barcode' => '8033153822901',
            'sn' => '23P_31W5U104I_01A',
            'product_name' => '唯品会测试商品A01',
            'size' => '',
            'not_delivery_num' => 0,
            'store_sn' => '',
            'security_type' => 0,
            'quality_check_flag' => 0,
            'pick_num' => 1
        ];
        $pick_product2 = [
            'pick_no' => $pick_sn,
            'warehouse' => 'VIPTEST01',
            'barcode' => '8033153822902',
            'art_no' => '23P_31W5U104I_01A',
            'product_name' => '唯品会测试商品A02',
            'size' => '',
            'not_delivery_num' => 0,
            'store_sn' => '',
            'security_type' => 0,
            'quality_check_flag' => 0,
            'pick_num' => 2
        ];

        $total = count($po_sns) * 2;
        $pick_detail_list = [];

        if ($page == 1) {
            foreach ($po_sns as $po_sn) {
                $pick_product1['po_no'] = $po_sn;
                $pick_product2['po_no'] = $po_sn;
                $pick_detail_list[] = $pick_product1;
                $pick_detail_list[] = $pick_product2;
            }
        }

        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'pick_detail_list' => $pick_detail_list
            ]
        ];
    }

    public function createPoDeliveryV2(Request $request)
    {
        $req = $request->get('createPoDeliveryReq');
        $logistics_no = $req['logistics_no'] ?? '';
        $delivery_method = $req['delivery_method'] ?? '1';
        $arrival_time = $req['arrival_time'];

        return [
            'returnCode' => '0',
            'result' => [
                'storage_no' => 'DE-' . rand(10000000, 99999999),
                'logistics_no' => $logistics_no,
                'delivery_method' => $delivery_method,
                'arrival_time' => $arrival_time,
            ]
        ];
    }

    public function importMultiPoDeliveryDetail(Request $request)
    {
        return [
            'returnCode' => '0',
            'result' => true
        ];
    }

    public function confirmDelivery(Request $request)
    {
        return [
            'returnCode' => '0',
            'result' => 1
        ];
    }

    public function cancelDelivery(Request $request)
    {
        return [
            'returnCode' => '0',
            'result' => [
                'return_code' => 'SUCCESS',
                'return_msg' => 'success'
            ]
        ];
    }

    public function getSkuStock(Request $request)
    {
        $vendor_id = $request->get('vendor_id');
        $barcode = $request->get('barcode');

        $product1 = [
            'barcode' => $barcode,
            'warehouse' => $vendor_id == 560 || $vendor_id == 20240717 ? '600185' : 'VIPTEST01',
            'cooperation_no' => '',
            'leaving_stock' => 0,
            'current_hold' => 0,
            'circuit_break_value' => 0,
            'area_warehouse_id' => '',
            'warehouse_flag' => 0,
            'unpaid_hold' => 0
        ];
        $result = [];
        $result[] = $product1;

        return [
            'returnCode' => '0',
            'result' => $result
        ];
    }

    public function updateInventory(Request $request)
    {
        return [
            'returnCode' => '0',
            'result' => true
        ];
    }

    public function getReturnInfo(Request $request)
    {
        $vendor_id = $request->get('vendor_id', '');
        $warehouse = $request->get('warehouse', '');
        $return_sn = $request->get('return_sn', '');
        $page = $request->get('page', 1);

        if ($vendor_id == 560) {
            return $this->_releaseGetReturnInfo($warehouse, $return_sn, $page);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetReturnInfo($warehouse, $return_sn, $page);
        }

        $returnInfo1 = [
            'return_sn' => '240422R01101CD',
            'warehouse' => 'VIP_NH',
            'return_type' => 3,
            'pay_type' => 1,
            'consignee' => 'zh',
            'country' => 'CN',
            'state' => '北京市',
            'city' => '北京市',
            'region' => '朝阳区',
            'town' => '双井街道',
            'address' => '北京市.北京市.朝阳区.双井街道.双井九龙花园',
            'postcode' => '',
            'telephone' => '',
            'mobile' => '16601166306',
            'to_email' => '',
            'cc_email' => '',
            'self_reference' => 0,
            'is_store_delivery' => 0,
            'return_address_no' => '',
            'posted_time' => date('Y-m-d H:i:s'),
            'out_time' => date('Y-m-d H:i:s'),
            'carrier_take_time' => '',
            'vendor_sign_time' => '',
            'vendor_confirm_time' => '',
            'return_status' => 0,
            'return_status_name' => '',
            'carrier_name' => '圆通',
            'carrier_code' => 'yuantong',
            'total_cases' => 1,
            'total_skus' => 1,
            'total_qtys' => 2,
            'origin_return_type' => '3'
        ];

        $total = 0;
        $returnInfos = [];

        if ($warehouse != 'VIP_NH') {
            return [
                'returnCode' => '0',
                'result' => [
                    'returnInfos' => $returnInfos,
                    'total' => $total
                ]
            ];
        }
        if ($return_sn && $return_sn == $returnInfo1['return_sn']) {
            $total = 1;
            $returnInfos[] = $returnInfo1;
        }
        if (!$return_sn) {
            $total = 1;
            if ($page == 1) {
                $returnInfos[] = $returnInfo1;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'returnInfos' => $returnInfos,
                'total' => $total
            ]
        ];
    }

    private function _releaseGetReturnInfo($warehouse, $return_sn, $page)
    {
        $returnInfo1 = [
            'return_sn' => '240428R02501CD',
            'warehouse' => 'VIP_BJ',
            'return_type' => 3,
            'pay_type' => 1,
            'consignee' => '张恒',
            'country' => 'CN',
            'state' => '北京市',
            'city' => '北京市',
            'region' => '朝阳区',
            'town' => '双井街道',
            'address' => '北京市.北京市.朝阳区.双井街道.双井九龙花园',
            'postcode' => '',
            'telephone' => '',
            'mobile' => '16601166306',
            'to_email' => '',
            'cc_email' => '',
            'self_reference' => 0,
            'is_store_delivery' => 0,
            'return_address_no' => '',
            'posted_time' => date('Y-m-d H:i:s'),
            'out_time' => date('Y-m-d H:i:s'),
            'carrier_take_time' => '',
            'vendor_sign_time' => '',
            'vendor_confirm_time' => '',
            'return_status' => 0,
            'return_status_name' => '',
            'carrier_name' => '圆通',
            'carrier_code' => 'yuantong',
            'total_cases' => 1,
            'total_skus' => 1,
            'total_qtys' => 2,
            'origin_return_type' => '3'
        ];

        return $this->_buildGetReturnInfo($warehouse, $return_sn, $page, $returnInfo1);
    }

    public function getReturnItem(Request $request)
    {
        $req = $request->get('req', []);
        $vendor_id = $req['vendor_id'];
        $return_sn = $req['return_sn'];
        $page = $req['page'];

        if ($vendor_id == 560) {
            return $this->_releaseGetReturnItem($return_sn, $page);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetReturnItem($return_sn, $page);
        }

        $item1 = [
            'box_no' => 'WP20240001',
            'po_no' => '1705501101',
            'barcode' => '8033153822901',
            'order_sn' => 'VIP202404221001',
            'qty' => 2,
            'schedule_id' => '17055001',
            'receipt_no' => '2024042201',
            'purchase_case_no' => 'YTO202404220001',
            'reference_no' => '',
            'work_number' => '',
            'is_jitx' => ''
        ];
        $item2 = [
            'box_no' => 'WP20240001',
            'po_no' => '1705501101',
            'barcode' => '8033153822902',
            'order_sn' => 'VIP202404221001',
            'qty' => 1,
            'schedule_id' => '17055001',
            'receipt_no' => '2024042201',
            'purchase_case_no' => 'YTO202404220001',
            'reference_no' => '',
            'work_number' => '',
            'is_jitx' => ''
        ];

        $items = [];
        if ($page == 1) {
            $items[] = $item1;
            $items[] = $item2;
        }

        return [
            'returnCode' => '0',
            'result' => [
                'return_sn' => $return_sn,
                'out_time' => date('Y-m-d H:i:s'),
                'total_cases' => 1,
                'total_sku' => 2,
                'total_qty' => 3,
                'total_detail' => 2,
                'items' => $items
            ]
        ];
    }

    private function _releaseGetReturnItem($return_sn, $page)
    {
        $item1 = [
            'box_no' => 'WP20245001',
            'po_no' => '2200801101',
            'barcode' => '8033153574403',
            'order_sn' => 'VIP02404251930000001',
            'qty' => 1,
            'schedule_id' => '22005001',
            'receipt_no' => '2024042701',
            'purchase_case_no' => 'YTO202404270001',
            'reference_no' => '',
            'work_number' => '',
            'is_jitx' => '1'
        ];
        $item2 = [
            'box_no' => 'WP20245001',
            'po_no' => '2200801101',
            'barcode' => '8033153574403',
            'order_sn' => 'VIPJIT02404251930001001',
            'qty' => 1,
            'schedule_id' => '22005001',
            'receipt_no' => '2024042701',
            'purchase_case_no' => 'YTO202404270002',
            'reference_no' => '',
            'work_number' => '',
            'is_jitx' => ''
        ];

        return $this->_buildGetReturnItem($return_sn, $page, $item1, $item2);
    }

    public function createChangeWarehouseWorkflow(Request $request)
    {
        $req = $request->get('changeWarehouseWorkflowReq', []);
        $workflow = $req['workflows'][0];

        return [
            'returnCode' => '0',
            'result' => [
                'total' => 1,
                'results' => [
                    [
                        'result' => 'SUCCESS',
                        'workflow_sn' => 'WF' . $workflow['order_sn'],
                        'request_id' => $workflow['request_id'],
                        'error_code' => '0',
                        'error_message' => ''
                    ]
                ]
            ]
        ];
    }

    public function getChangeWarehouseWorkflows(Request $request)
    {
        $req = $request->get('changeWarehouseWorkflowReq', []);
        $vendor_id = $req['vendor_id'];
        $page = $req['page'];

        if ($vendor_id == 560) {
            return $this->_releaseGetChangeWarehouseWorkflows($page, $vendor_id);
        } else if ($vendor_id == 20240717) {
            return $this->_uatGetChangeWarehouseWorkflows($page, $vendor_id);
        }

        $orderSn = 'VIP202405251001';
        $result1 = [
            'workflow_sn' => 'WF' . $orderSn,
            'vendor_id' => $vendor_id,
            'order_sn' => $orderSn,
            'request_id' => '58845c86-2c5f-11ef-a108-0242ac' . rand(111111, 999999),
            'workflow_state' => '300',
            'old_delivery_warehouse' => 'VIPTEST01',
            'new_delivery_warehouse' => 'VIPTEST02',
            'update_time' => time(),
            'reject_remark' => '',
        ];

        $total = 1;
        $results = [];
        if ($page == 1) {
            $results[] = $result1;
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'results' => $results
            ]
        ];
    }

    private function _releaseGetChangeWarehouseWorkflows($page, $vendor_id)
    {
        $orderSn = 'VIP02405281930000001';
        $result1 = [
            'workflow_sn' => 'WF' . $orderSn,
            'vendor_id' => $vendor_id,
            'order_sn' => $orderSn,
            'request_id' => '58845c86-2c5f-11ef-a108-0242ac' . rand(111111, 999999),
            'workflow_state' => '300',
            'old_delivery_warehouse' => '600185',
            'new_delivery_warehouse' => '600186',
            'update_time' => time(),
            'reject_remark' => '',
        ];

        return $this->_buildGetChangeWarehouseWorkflows($page, $result1);
    }

    public function getSkuPriceInfo(Request $request)
    {
        return [
            'returnCode' => '0',
            'result' => [
                'price_list' => [
                    [
                        'barcode' => $this->uatGoodBarCode,
                        'actual_market_price' => '100',
                        'actual_unit_price' => '95',
                    ],
                    [
                        'barcode' => $this->uatGoodBarCode2,
                        'actual_market_price' => '100',
                        'actual_unit_price' => '95',
                    ],
                    [
                        'barcode' => '8033153822901',
                        'actual_market_price' => '100',
                        'actual_unit_price' => '95',
                    ],
                    [
                        'barcode' => '8033153822902',
                        'actual_market_price' => '120',
                        'actual_unit_price' => '115',
                    ],
                    [
                        'barcode' => '8033153574403',
                        'actual_market_price' => '165.32',
                        'actual_unit_price' => '160',
                    ],
                    [
                        'barcode' => '8033153850484',
                        'actual_market_price' => '203',
                        'actual_unit_price' => '200',
                    ],
                ]
            ]
        ];
    }

    public function getJitOrderDetailAndPrice(Request $request)
    {
        $req = $request->get('request', []);
        $pick_sn = $req['pick_no'];
        $page = $req['page_no'];

        $po_sn = substr($pick_sn, strpos($pick_sn, '-') + 1);
        $order_detail_list = [];
        if ($page == 1) {
            $order_detail_list = [
                [
                    'order_sn' => 'VIP202404221001',
                    'po' => $po_sn,
                    'pick_no' => $po_sn,
                    'good_sn' => $this->uatGoodBarCode,
                    'bill_tax_price' => '100',
                    'bill_price' => '95',
                ],
                [
                    'order_sn' => 'VIP202404221001',
                    'po' => $po_sn,
                    'pick_no' => $po_sn,
                    'good_sn' => $this->uatGoodBarCode2,
                    'bill_tax_price' => '100',
                    'bill_price' => '95',
                ],
                [
                    'order_sn' => 'VIP202404221001',
                    'po' => $po_sn,
                    'pick_no' => $po_sn,
                    'good_sn' => '8033153822901',
                    'bill_tax_price' => '100',
                    'actual_unit_price' => '95',
                ],
                [
                    'order_sn' => 'VIP202404221001',
                    'po' => $po_sn,
                    'pick_no' => $po_sn,
                    'good_sn' => '8033153822902',
                    'bill_tax_price' => '120',
                    'bill_price' => '115',
                ],
                [
                    'order_sn' => 'VIP202404221001',
                    'po' => $po_sn,
                    'pick_no' => $po_sn,
                    'good_sn' => '8033153574403',
                    'bill_tax_price' => '165.32',
                    'bill_price' => '160',
                ],
                [
                    'order_sn' => 'VIP202404221001',
                    'po' => $po_sn,
                    'pick_no' => $po_sn,
                    'good_sn' => '8033153850484',
                    'bill_tax_price' => '203',
                    'bill_price' => '200',
                ],
            ];
        }

        return [
            'returnCode' => '0',
            'result' => [
                'result' => [
                    'status' => '200',
                    'message' => ''
                ],
                'total' => 6,
                'order_detail_list' => $order_detail_list
            ]
        ];
    }

    public function getWarehouses(Request $request)
    {
        $req = $request->get('request', []);
        $vendor_id = $req['vendor_id'];

        if ($vendor_id == 560 || $vendor_id == 20240717) {
            return $this->_buildGetWarehouses();
        }

        return [
            'returnCode' => '0',
            'result' => [
                [
                    'warehouse_code' => 'VIPTEST01',
                    'warehouse_name' => '唯品会测试1号仓',
                    'warehouse_address' => '双井',
                    'warehouse_type' => '0',
                    'is_pre_transport_no' => '0',
                    'is_active' => true,
                    'province_ame' => '北京',
                    'city_name' => '北京市',
                    'region_name' => '朝阳区',
                    'town_name' => '',
                ]
            ]
        ];
    }

    public function getCarrierList(Request $request)
    {
        $req = $request->get('carrierRequest', []);
        $page = $req['page'];

        $carrier1 = [
            'tms_carrier_id' => '1101',
            'carrier_name' => '顺丰速运',
            'carrier_shortname' => '顺丰',
            'carrier_code' => 'shunfeng',
            'carrier_isvalid' => 1,
        ];
        $carrier2 = [
            'tms_carrier_id' => '1102',
            'carrier_name' => '圆通速递',
            'carrier_shortname' => '圆通',
            'carrier_code' => 'yuantong',
            'carrier_isvalid' => 1,
        ];
        $carrier3 = [
            'tms_carrier_id' => '1103',
            'carrier_name' => '中通速递',
            'carrier_shortname' => '中通',
            'carrier_code' => 'zhongtong',
            'carrier_isvalid' => 1,
        ];
        $carrier4 = [
            'tms_carrier_id' => '2100',
            'carrier_name' => '唯品专配',
            'carrier_shortname' => '唯品',
            'carrier_code' => '120001552',
            'carrier_isvalid' => 1,
        ];

        $carriers = [];
        if ($page == 1) {
            $carriers[] = $carrier1;
            $carriers[] = $carrier2;
            $carriers[] = $carrier3;
            $carriers[] = $carrier4;
        }

        return [
            'returnCode' => '0',
            'result' => [
                'carriers' => $carriers,
                'total' => 4
            ]
        ];
    }

    private function _uatGetSkuList($barcode, $page)
    {
        $vip_list = [
            [
                'barcode' => $this->uatGoodBarCode,
                'product_name' => '女士T恤黑色 L',
                'sn' => '23P_3096D1042_100',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => time()
            ],
            [
                'barcode' => $this->uatGoodBarCode2,
                'product_name' => '女士T恤黑色 M',
                'sn' => '23P_3096D1042_100',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => time()
            ],
            [
                'barcode' => '8033153621367',
                'product_name' => '女士T恤黑色 S',
                'sn' => '23P_3096D1042_100',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => time()
            ],
            [
                'barcode' => '8033153621510',
                'product_name' => '女士T恤黑色 XS',
                'sn' => '23P_3096D1042_100',
                'selling_status' => 1,
                'cooperation_no' => '30011001',
                'warehouse' => '',
                'latest_update_time' => time()
            ],
        ];

        return $this->_buildGetSkuList($barcode, $page, $vip_list);
    }

    private function _buildGetSkuList($barcode, $page, $vip_list = [])
    {
        $list = [];
        if (!$barcode) {
            if ($page == 1) {
                $list = $vip_list;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'has_next' => false,
                'list' => $list
            ]
        ];
    }

    private function _uatGetJitXOrdersAndPrice($order_sn, $page, $vendor_id)
    {
        $goods = [
            "vendor_code" => (string)$vendor_id,
            "quantity" => 1,
            "anti_theft_flag" => "0",
            "brand_name" => "测试品牌",
            "product_name" => "女士T恤黑色 L",
            "promotion_price" => "",
            "size" => "L",
            "quality_check_type" => 0,
            "price" => "165.32",
            "vendor_id" => $vendor_id,
            "check_items" => [],
            "sn" => "23P_3096D1042_100",
            "cooperation_no" => "30011001",
            "quality_check_type_desc" => "",
            "barcode" => $this->uatGoodBarCode,
            "security_type" => 0,
            "po_no" => $this->uatPoSn,
        ];

        $order1 = [
            "is_province_dw_order" => 0,
            "buyer_province" => "北京市",
            "transport_time" => "",
            "buyer_country_id" => "CN",
            "remark" => "",
            "forbidden_reason" => "",
            "transport_no" => "",
            "merged_sn" => "",
            "order_status" => "10",
            "delivery_kpi_start_time" => "",
            "buyer_mobile" => "166****6306",
            "order_goods" => [
                $goods
            ],
            "pay_type" => "微信支付app",
            "transport_day" => "送货时间不限",
            "parent_order_sn" => "",
            "cod_type" => "0",
            "is_forbidden_delivery" => 0,
            "is_pre_transport_no" => "0",
            "regular_delivery" => 0,
            "carrier_name" => "",
            "order_type" => 1,
            "buyer_county" => "朝阳区",
            "cod_money" => "0.00",
            "delivery_warehouse" => "600185",
            "buyer_address" =>
                "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "buyer_postcode" => "100020",
            "action_list" => [],
            "vendor_name" => "贝纳通（上海）商贸有限公司",
            "old_order_sn" => "",
            "buyer_city" => "北京市",
            "buyer" => "ZH",
            "merged_code" => "2A12A2837A338DD33B49642313240001",
            "last_update_time" => date('Y-m-d H:i:s'),
            "buyer_tel" => "",
            "is_store_delivery" => 0,
            "vendor_id" => $vendor_id,
            "add_time" => date('Y-m-d H:i:s'),
            "order_sn" => $this->uatOrderSn,
            "carrier_code" => "",
        ];

        return $this->_buildGetJitXOrdersAndPrice($order_sn, $page, $order1);
    }

    private function _buildGetJitXOrdersAndPrice($order_sn, $page, $order1 = [], $order2 = [])
    {
        $total = 0;
        $orders = [];
        if (!$order_sn) {
            $total = 1;
            if ($page == 1) {
                $orders[] = $order1;
                //$orders[] = $order2;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'orders' => $orders
            ]
        ];
    }

    private function _uatGetDeliveryOrders($page, $vendor_id)
    {
        $details = [
            "brand_name" => "测试品牌",
            "product_name" => "女士T恤黑色 L",
            "barcode" => $this->uatGoodBarCode,
            "size" => "L",
            "quantity" => 1,
            "po_no" => $this->uatPoSn,
            "cooperation_no" => "30011001",
            "price" => "165.32"
        ];

        $order1 = [
            "order_sn" => $this->uatOrderSn,
            "available_warehouses" => [
                "600185"
            ],
            "status" => "NEW",
            "status_remark" => "新增",
            "buyer_address" => "北京市.北京市.朝阳区.双井街道广渠路31号院北汽资产大厦1号楼5层兴长信达科技有限公司",
            "update_time" => date('Y-m-d H:i:s'),
            "delivery_order_details" => [
                $details
            ],
            "vendor_id" => $vendor_id,
            "confirmed_delivery_warehouse" => "",
            "order_type" => 1,
            "buyer_province" => "北京市",
            "buyer_city" => "北京市",
            "buyer_county" => "朝阳区",
            "is_store_delivery" => 0,
            "root_order_sn" => ""
        ];

        return $this->_buildGetDeliveryOrders($page, $order1);
    }

    private function _buildGetDeliveryOrders($page, $order1 = [])
    {
        $total = 1;
        $orders = [];
        if ($page == 1) {
            $orders[] = $order1;
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'delivery_orders' => $orders
            ]
        ];
    }

    private function _uatGetPoList($po_no, $page)
    {
        $poList = [
            "vendor_name" => "贝纳通（上海）商贸有限公司",
            "brand_name" => "测试品牌",
            "warehouse" => "600185",
            "schedule_name" => "测试档期",
            "co_mode" => "jit",
            "trade_mode" => "",
            "po_start_time" => date('Y-m-d H:i:s'),
            "sell_et_time" => date('Y-m-d H:i:s', strtotime('+1 Year')),
            "not_pick" => "0",
            "stock" => "0",
            "schedule_id" => "22005001",
            "po_no" => $this->uatPoSn,
            "sell_st_time" => date('Y-m-d H:i:s'),
            "sales_volume" => "0",
            "cooperation_no" => "30011001",
        ];

        return $this->_buildGetPoList($po_no, $page, $poList);
    }

    private function _buildGetPoList($po_no, $page, $poList = [])
    {
        $total = 0;
        $purchase_order_list = [];
        if ($po_no && $po_no == $poList['po_no']) {
            $total = 1;
            $purchase_order_list[] = $poList;
        }
        if (!$po_no) {
            $total = 1;
            if ($page == 1) {
                $purchase_order_list[] = $poList;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'purchase_order_list' => $purchase_order_list
            ]
        ];
    }

    private function _uatGetPickDetail($pick_no, $po_no, $page)
    {
        $pick_product1 = [
            'barcode' => $this->uatGoodBarCode,
            'art_no' => '23P_3096D1042_100',
            'product_name' => '女士T恤黑色 L',
            'size' => 'L',
            'not_delivery_num' => 0,
            'security_type' => 0,
            'quality_check_flag' => 0,
            'stock' => 5
        ];

        $pick_product2 = [
            'barcode' => $this->uatGoodBarCode2,
            'art_no' => '23P_3096D1042_100',
            'product_name' => '女士T恤黑色 M',
            'size' => 'M',
            'not_delivery_num' => 0,
            'security_type' => 0,
            'quality_check_flag' => 0,
            'stock' => 5
        ];


        return $this->_buildGetPickDetail($po_no, $page, $pick_product1, $pick_product2);
    }

    private function _buildGetPickDetail($po_no, $page, $pick_product1 = [], $pick_product2 = [])
    {
        $total = 2;
        $pick_product_list = [];

        $res = [
            'po_no' => $po_no,
            'sell_st_time' => date('Y-m-d H:i:s'),
            'sell_et_time' => date('Y-m-d H:i:s', strtotime('+1 Year')),
            'export_time' => "",
            'export_num' => 0,
            'warehouse' => '600185',
            'order_cate' => '',
            'total' => $total,
            'store_sn' => '',
            'jit_type' => ''
        ];

        if ($page == 1) {
            $pick_product_list[] = $pick_product1;
            $pick_product_list[] = $pick_product2;
        }
        $res['pick_product_list'] = $pick_product_list;

        return [
            'returnCode' => '0',
            'result' => $res
        ];
    }

    private function _buildGetMultiPoPickDetail()
    {
        return [
            'returnCode' => '0',
            'result' => [
                'total' => 0,
                'pick_detail_list' => []
            ]
        ];
    }

    private function _uatGetReturnInfo($warehouse, $return_sn, $page)
    {
        $returnInfo1 = [
            'return_sn' => $this->uatReturnSn,
            'warehouse' => 'VIP_BJ',
            'return_type' => 3,
            'pay_type' => 1,
            'consignee' => '张恒',
            'country' => 'CN',
            'state' => '北京市',
            'city' => '北京市',
            'region' => '朝阳区',
            'town' => '双井街道',
            'address' => '北京市.北京市.朝阳区.双井街道.双井九龙花园',
            'postcode' => '',
            'telephone' => '',
            'mobile' => '16601166306',
            'to_email' => '',
            'cc_email' => '',
            'self_reference' => 0,
            'is_store_delivery' => 0,
            'return_address_no' => '',
            'posted_time' => date('Y-m-d H:i:s'),
            'out_time' => date('Y-m-d H:i:s'),
            'carrier_take_time' => '',
            'vendor_sign_time' => '',
            'vendor_confirm_time' => '',
            'return_status' => 0,
            'return_status_name' => '',
            'carrier_name' => '圆通',
            'carrier_code' => 'yuantong',
            'total_cases' => 1,
            'total_skus' => 1,
            'total_qtys' => 2,
            'origin_return_type' => '3'
        ];

        return $this->_buildGetReturnInfo($warehouse, $return_sn, $page, $returnInfo1);
    }

    private function _buildGetReturnInfo($warehouse, $return_sn, $page, $returnInfo1)
    {
        $total = 0;
        $returnInfos = [];

        if ($warehouse != 'VIP_BJ') {
            return [
                'returnCode' => '0',
                'result' => [
                    'returnInfos' => $returnInfos,
                    'total' => $total
                ]
            ];
        }
        if ($return_sn && $return_sn == $returnInfo1['return_sn']) {
            $total = 1;
            $returnInfos[] = $returnInfo1;
        }
        if (!$return_sn) {
            $total = 1;
            if ($page == 1) {
                $returnInfos[] = $returnInfo1;
            }
        }
        return [
            'returnCode' => '0',
            'result' => [
                'returnInfos' => $returnInfos,
                'total' => $total
            ]
        ];
    }

    private function _uatGetReturnItem($return_sn, $page)
    {
        $item1 = [
            'box_no' => 'WP20245001',
            'po_no' => $this->uatPoSn,
            'barcode' => $this->uatGoodBarCode,
            'order_sn' => $this->uatOrderSn,
            'qty' => 1,
            'schedule_id' => '22005001',
            'receipt_no' => '2024071701',
            'purchase_case_no' => 'YTO' . $this->uatPoSn,
            'reference_no' => '',
            'work_number' => '',
            'is_jitx' => '1'
        ];
        $item2 = [
            'box_no' => 'WP20245001',
            'po_no' => $this->uatPoSn,
            'barcode' => $this->uatGoodBarCode2,
            'order_sn' => $this->uatOrderSn2,
            'qty' => 1,
            'schedule_id' => '22005001',
            'receipt_no' => '2024071701',
            'purchase_case_no' => 'YTO20240717002',
            'reference_no' => '',
            'work_number' => '',
            'is_jitx' => ''
        ];

        return $this->_buildGetReturnItem($return_sn, $page, $item1, $item2);
    }

    private function _buildGetReturnItem($return_sn, $page, $item1 = [], $item2 = [])
    {
        $items = [];
        if ($page == 1) {
            $items[] = $item1;
            $items[] = $item2;
        }

        return [
            'returnCode' => '0',
            'result' => [
                'return_sn' => $return_sn,
                'out_time' => date('Y-m-d H:i:s'),
                'total_cases' => 1,
                'total_sku' => 1,
                'total_qty' => 2,
                'total_detail' => 2,
                'items' => $items
            ]
        ];
    }

    private function _uatGetChangeWarehouseWorkflows($page, $vendor_id)
    {
        $orderSn = $this->uatOrderSn;
        $result1 = [
            'workflow_sn' => 'WF' . $orderSn,
            'vendor_id' => $vendor_id,
            'order_sn' => $orderSn,
            'request_id' => '58845c86-2c5f-11ef-a108-0242ac' . rand(111111, 999999),
            'workflow_state' => '300',
            'old_delivery_warehouse' => '600185',
            'new_delivery_warehouse' => '600186',
            'update_time' => time(),
            'reject_remark' => '',
        ];

        return $this->_buildGetChangeWarehouseWorkflows($page, $result1);
    }

    private function _buildGetChangeWarehouseWorkflows($page, $result1 = [])
    {
        $total = 1;
        $results = [];
        if ($page == 1) {
            $results[] = $result1;
        }
        return [
            'returnCode' => '0',
            'result' => [
                'total' => $total,
                'results' => $results
            ]
        ];
    }

    private function _buildGetWarehouses()
    {
        return [
            'returnCode' => '0',
            'result' => [
                [
                    'warehouse_code' => '600185',
                    'warehouse_name' => '贝纳通唯品会仓库',
                    'warehouse_address' => '双井',
                    'warehouse_type' => '0',
                    'is_pre_transport_no' => '0',
                    'is_active' => true,
                    'province_ame' => '北京',
                    'city_name' => '北京市',
                    'region_name' => '朝阳区',
                    'town_name' => '',
                ]
            ]
        ];
    }
}
